package cc.jethro.jdxyq.homeActividadesRecycler;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import cc.jethro.jdxyq.R;
import cc.jethro.jdxysdk.ImgUtil.ImgLoader;

/**
 * Created by jethro on 2017/5/13.
 */

public class ActividadesAdapter extends RecyclerView.Adapter<ActividadesAdapter.ViewHolder> {

    //活动入口的数据对象集
    private Context context ;
    private List<Actividades> actividadesList ;

    //初始化item view
    class ViewHolder extends RecyclerView.ViewHolder {
        public TextView titleView ;
        public TextView contenView ;
        public ImageView iconView ;

        public ViewHolder(View itemView) {
            super(itemView);
            titleView = (TextView) itemView.findViewById(R.id.item_ac_title);
            contenView = (TextView) itemView.findViewById(R.id.item_ac_content);
            iconView = (ImageView) itemView.findViewById(R.id.item_ac_icon);
        }
    }

    public ActividadesAdapter( Context context , List<Actividades> actividadesList ) {
        this.actividadesList = actividadesList;
        this.context = context.getApplicationContext();
    }


    //加载布局
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_ac_entrance, parent,false);

        return new ViewHolder(view);
    }


    /**
     * 绑定数据
     * @param holder
     * @param position 当前显示的数据指针
     */
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Actividades actividades = actividadesList.get(position);
        holder.titleView.setText(actividades.getTitle());
        holder.contenView.setText(actividades.getContent());
        ImgLoader.INSTANCE.loadImg(context
                ,actividades.getIcon()
                ,holder.iconView);
    }

    @Override
    public int getItemCount() {
        return actividadesList.size();
    }
}
